package com.dot.dominion.domain;

public class PlayingDeck{
	protected Deck deck;		//Deck to draw from
	protected Deck discardPile;	//Deck to discard to
	
	/**
	 * Basic constructor for PlayingDeck
	 */
	public PlayingDeck() {
		deck = new Deck();
		discardPile = new Deck();
	}
	
	/**
	 * Add a card obtained via Buy to the playing deck
	 * 
	 * @param card		Card to add to the playing deck
	 */
	public void addBuyCard( Card card ) {
		discardPile.addToDeck( card );
	}
	
	/**
	 * Add a card gained to the playing deck
	 * 
	 * @param card		Card to add to the playing deck
	 */
	public void addGainCard( Card card ) {
		discardPile.addToDeck( card );
	}
	
	/**
	 * Add a card to the top of the draw deck
	 * 
	 * @param card		Card to add to the deck
	 */
	public void addToDeck( Card card ) {
		deck.addToDeck( card );
	}
	
	/**
	 * Discard the top card of the draw deck
	 */
	public void discardTopCard() {
		discardPile.addToDeck( deck.draw() );
	}
	
	/**
	 * Draw a card from the top of the draw deck
	 * 
	 * @return	The card at the top of the draw deck
	 * 			null, if the deck is empty
	 */
	public Card draw() {
		if( deck.isEmpty() )
			shuffleAll();
		
		// Can't return anything if the draw deck is empty
		if( deck.isEmpty() )
			return null;
		else
			return deck.draw();
	}
	
	/**
	 * Shuffle the draw deck
	 */
	public void shuffle() {
		deck.shuffle();
	}
	
	/**
	 * Shuffle the entire playing deck
	 */
	public void shuffleAll() {
		while(! discardPile.isEmpty() )
			deck.addToDeck( discardPile.draw() );
		
		shuffle();
	}
}
